package com.lizhi.yun.sync.rsz.handler;/**
 * @program: hbsf_yun
 * @name RszTrainPatientSyncHandler
 * @description: 接收正在训练的患者信息
 * @author: lizhi
 * @create: 2021-11-29 09:32
 */

import com.lizhi.common.yun.entity.RpcPatientPOJO;
import com.lizhi.common.yun.entity.RpcServicePOJO;
import com.lizhi.common.yun.enums.HeartBeartEnum;
import com.lizhi.utils.cache.MemoryCacheUtil;
import com.lizhi.utils.json.SamJsonUtil;
import com.lizhi.yun.db.rsz.entity.RszPatientEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 *@program: hbsf_yun
 *@name RszTrainPatientSyncHandler
 *@description: 接收正在训练的患者信息
 *@author: lizhi
 *@create: 2021-11-29 09:32
 */
@Slf4j
@Service
public class RszTrainPatientSyncHandler {

    public String recv(String json){
        RpcServicePOJO rpcServicePOJO = new RpcServicePOJO();
        try{
            RszPatientEntity rszPatientEntity = SamJsonUtil.toObject(json, RszPatientEntity.class);
            log.info("康复磨砂卓正在训练的患者信息上传:{}", rszPatientEntity);
            RpcPatientPOJO rpcPatientPOJO = new RpcPatientPOJO();
            rpcPatientPOJO.setPtId(rszPatientEntity.ptId);
            rpcPatientPOJO.setPtNm(rszPatientEntity.ptNm);
            rpcPatientPOJO.setPtSex(rszPatientEntity.ptSex);
            rpcPatientPOJO.setPtSexText(rszPatientEntity.ptSexText);
            rpcPatientPOJO.setPtAge(rszPatientEntity.ptAge);
            rpcPatientPOJO.setPtPhone(rszPatientEntity.ptPhone);
            rpcPatientPOJO.setHospitalId(rszPatientEntity.getHospitalId());
            rpcPatientPOJO.setHospitalSystemId(rszPatientEntity.getHospitalSystemId());
            /*放入到缓存中*/
            MemoryCacheUtil.put(rpcPatientPOJO.getHospitalId() + "-" + rpcPatientPOJO.getHospitalSystemId(), rpcPatientPOJO, 40000);
            rpcServicePOJO.setErrorCode(HeartBeartEnum.HEART_BEART_000000.getEnValue());
            rpcServicePOJO.setMessage(HeartBeartEnum.HEART_BEART_000000.getEnName());
        }catch (Exception e){
            e.printStackTrace();
        }
        return SamJsonUtil.toJson(rpcServicePOJO);
    }
}
